<script>

import {ElNotification} from "element-plus";
import {loadAdminClass, removeAdminClass} from "@/api/admin/class.js";

export default {
  data(){
    return {
      totle: 0,
      params: {
        pageNo: 1,
        pageSize: 5,
        major:'',
        department:'',
        cname:''
      },
      list: [],
    }
  },
  methods: {
    async initClassData(){
      let data = await loadAdminClass(this.params)
      this.totle = data.total;
      this.list = data.list;
    },
    async deleteClass(row){
      await removeAdminClass(row.class_id);
      ElNotification.success({
        title:`“${row.class_name}”删除成功`,
      })
      this.initClassData()
    },
  },
  created() {
    this.initClassData()
  }
}
</script>
<template>
    <el-card>
        <template #header>班级管理</template>
        <div class="nav-bar">
            <div class="search">
                <el-input size="small" placeholder="系名" clearable v-model="params.department"></el-input>
                <el-input size="small" placeholder="专业名" clearable v-model="params.major"></el-input>
                <el-input size="small" placeholder="班级名" clearable v-model="params.cname"></el-input>
                <el-button size="small" type="primary" @click="initClassData()">
                    <template #icon>
                        <el-icon><EpSearch /></el-icon>
                    </template>
                    <span>查询</span>
                </el-button>
            </div>
            <div>
                <el-button size="small" type="success">
                    <template #icon>
                        <el-icon><EpPlus /></el-icon>
                    </template>
                    <span>添加</span>
                </el-button>
            </div>
        </div>
        <el-table border stripe size="small" :data="list">
            <template #empty>
                <el-result title="暂无数据">
                    <template #icon>
                        <el-empty description="暂无数据" />
                    </template>
                </el-result>
            </template>
            <el-table-column label="序号" type="index" width="60"></el-table-column>
            <el-table-column label="班级名称" prop="class_name"></el-table-column>
            <el-table-column label="年级" prop="class_grade"></el-table-column>
            <el-table-column label="所属专业" prop="major_name"></el-table-column>
            <el-table-column label="所属系" prop="department_name"></el-table-column>
            <el-table-column label="操作" width="120" #default="{row}">
                <el-button type="primary" link>编辑</el-button>
              <el-popconfirm :title="`是否删除班级“${row.class_name}”`" @confirm="deleteClass(row)">删除
                <template #reference>
                  <el-button type="danger" link>删除</el-button>
                </template>
              </el-popconfirm>
            </el-table-column>
        </el-table>
        <el-pagination size="small" background
            layout="total, sizes, prev, pager, next, jumper"
            :page-sizes="[5,10,20,30,40,50]"
            :total="totle"
            v-model:page-size="params.pageSize"
            v-model:current-page="params.pageNo"
            @change="initClassData()"
        />
    </el-card>

</template>

<style scoped>
.nav-bar{
    display: flex;
    flex-flow: row nowrap;
    justify-content: space-between;
    margin-bottom: 14px;
}
.nav-bar .el-input{
    width: 180px;
    margin-right: 10px;
}
.el-pagination{
    margin-top: 14px;
    justify-content: center;
}
</style>
